/****************************************************************************
 *
 * Copyright (C) 2003-2008 Los Alamos National Security, LLC
 *                         Packet Analytics Corporation
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 2 as
 * published by the Free Software Foundation.  You may not use, modify or
 * distribute this program under any other version of the GNU General
 * Public License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ****************************************************************************/
package nfse.query;

import java.io.*;

public class ProcessFinisher extends Thread {
	private Process p = null;
	private long startTS = 0;
	private String command = "";

	public ProcessFinisher(Process p, long startTS, String command) {
		this.p = p;
		this.startTS = startTS;
		this.command = command;
	}

	public void run() {
		int val = -1;
		try {
			DataInputStream in = new DataInputStream(p.getInputStream());
			int b = 0;
			while (b != -1)
				b = in.read();
		} catch (Exception E) {
			// no op
		}
		try {
			val = p.waitFor();
		} catch (Exception E) {
			// no op
		}
		long stopTS = System.currentTimeMillis();
		System.out.println(
			"Process returned with exit code " + val + ". Time taken was " + (stopTS - startTS) / 1000 + " seconds.");
		if (val == 129) {
			System.out.println("****** Failed command line: " + command);
			//System.exit(1);
			//System.out.println("Failed command line: " + command);
		}
	}
}
